package com.cx.android;

import android.app.IntentService;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViewsService;
import android.widget.RemoteViews;
import android.appwidget.AppWidgetManager;

public class Code1009IntentService extends IntentService 
{
	public Code1009IntentService() 
	{
		super("Code1009IntentService");
	}

	public Code1009IntentService(String name) 
	{
		super(name);
	}

	@Override
	protected void onHandleIntent(Intent intent) 
	{
		final String action = intent.getAction();

		if (action.equals(Code1009Intents.ACTION_REFRESH_WIDGETS)) 
		{
			refreshWidgets(intent);
		}
		if (action.equals(Code1009Intents.ACTION_SHOW_CODE1009)) 
		{	
			refreshWidgets(intent);
		}
	}

	private void refreshWidgets(Intent intent) 
	{
		updateAllWidgets();
	}

	private void updateAllWidgets() 
	{
		int i, len;
		final AppWidgetManager widgetManager = getAppWidgetManager();
		//VolumeWidgetUpdateInfo info;

		final int[] ids = widgetManager.getAppWidgetIds(new ComponentName(this, Code1009AppWidgetProvider.class));
		len = ids.length;
		for (i = 0; i < len; i++) 
		{
			//info = VolumeWidgetUpdateInfo.createInstance(this, ids3x1[i]);
			Code1009AppWidgetProvider.UpdateWidget(this, widgetManager, ids[i] /*, info*/ );
		}
	}

	public static Intent getServiceIntent(Context context, String action) 
	{
		final Intent intent = new Intent(context, Code1009IntentService.class);
		intent.setAction(action);
		return intent;
	}
	
	private AppWidgetManager mAppWidgetManager = null;

	private AppWidgetManager getAppWidgetManager() 
	{
		if (mAppWidgetManager == null) 
		{
			mAppWidgetManager = AppWidgetManager.getInstance(this);
		}

		return mAppWidgetManager;
	}
}
